package leecode;

import java.util.Arrays;

/**
 * @author csp 2021-04-25
 */
public class BubbleSort {
    public static void main(String[] args) {
        BubbleSort sort = new BubbleSort();
        int[] nums = new int[]{5, 4, 3, 2, 1,2,2,4,1};
        sort.sort(nums);
        System.out.println(Arrays.toString(nums));
    }

    public void sort(int[] nums) {
        for (int i = nums.length - 1; i >= 0; i--) {
            for (int j = 0; j < i; j++) {
                int p1 = nums[j];
                int p2 = nums[j + 1];
                if (p1 > p2) {
                    nums[j] = p2;
                    nums[j + 1] = p1;
                }
            }

        }
    }
}
